
var Grid = require('Grid')
var BoardData = require('BoardData')
var BoardView = require('BoardView')

cc.Class({
    extends: cc.Component,

    properties: {
        boardData: {
            default: null,
            type: cc.Node,
        },

        boardView: {
            default: null,
            type: cc.Node,
        },

    },

    onLoad: function () {
        this.boardData = this.boardData.getComponent(BoardData);
        this.boardView = this.boardView.getComponent(BoardView);
        this.init();
    },

    init: function () {
        this.boardData.init();
        let gridDataMap = this.boardData.gridDataMap;
	    for (var key in gridDataMap) {
	        if (gridDataMap.hasOwnProperty(key)) {
	            var gridData = gridDataMap[key];
	            let grid = cc.instantiate(this.boardView.gridPrefab);
	            grid.getComponent(Grid).setFillColor(gridData.index, gridData.x, gridData.y);
                grid.x = gridData.x * (grid.getContentSize().width / 2 + 0)
                grid.y = gridData.y * (grid.getContentSize().height - 23 * grid.getScaleY())
                grid.parent = this.boardView.plane;
           }
       }
    },

    onMainBtnClick: function () {
        cc.director.loadScene('Menu');
    },

});
